home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / bcpp / cmmdlg / fnamedlg.pas < prev    next >
Pascal/Delphi Source File  |  1992-08-31  |  5KB  |  187 lines

  1. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  2. {   \\\                                    }
  3. {  -(j)-                                   }
  4. {    /juanca                               }
  5. {    ~                                     }
  6. {$D ⌐ ACASA 1989-1992, All rights reserved }
  7. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  8.  
  9. UNIT FNAMEDLG;
  10. {$C MOVEABLE DEMANDLOAD DISCARDABLE}
  11. INTERFACE
  12.   USES
  13.     WINTYPES,
  14.     WOBJECTS,
  15.     COMMDLG,
  16.     COMONDLG;
  17.  
  18.  
  19.   TYPE
  20.     pFileNameDlg = ^tFileNameDlg;
  21.     tFileNameDlg = OBJECT ( tCommonDlg )
  22.  
  23.       openFileName :tOpenFileName;
  24.       filePath,
  25.       fileName     :tCString;
  26.       toOpen       :Boolean; 
  27.  
  28.  
  29.       CONSTRUCTOR
  30.       init(iparent:PWindowsObject; name :PChar; iToOpen :Boolean);
  31.  
  32.       FUNCTION
  33.       defSpec :PChar;
  34.         virtual;
  35.  
  36.       FUNCTION
  37.       defExt :PChar;
  38.         virtual;
  39.  
  40.       FUNCTION
  41.       defSpecPos:Byte;
  42.         virtual;
  43.  
  44.       FUNCTION
  45.       openFlags :Longint;
  46.         virtual;
  47.  
  48.       FUNCTION
  49.       doExec:Boolean;
  50.         virtual;
  51.  
  52.       FUNCTION
  53.       execute:Integer;
  54.         virtual;
  55.  
  56.     END;
  57.  
  58. {****************************************************************}
  59. IMPLEMENTATION
  60.  
  61.  
  62.       CONSTRUCTOR
  63.       tFileNameDlg.
  64.       {}
  65.       init(iparent:PWindowsObject; name :PChar; iToOpen :Boolean);
  66.         begin
  67.           tCommonDlg.init(iparent, name);
  68.           toOpen := iToOpen;
  69.           fillChar(filePath, sizeOf(filePath), #0);
  70.           fillChar(fileName, sizeOf(fileName), #0);
  71.           FillChar(openFileName, SizeOf(TOpenFileName), #0);
  72.         end;
  73.  
  74.       FUNCTION
  75.       tFileNameDlg.
  76.       {}
  77.       defSpec :PChar;
  78.         begin
  79.           defSpec := 'All Files (*.*)'#0'*.*'#0'Override this(!@$%.#%!)'#0'!@$%.#%!'#0'TextFiles (*.txt)'#0'*.txt'#0
  80.         end;
  81.  
  82.       FUNCTION
  83.       tFileNameDlg.
  84.       {}
  85.       defSpecPos:Byte;
  86.         begin
  87.           defSpecPos := 1 {of the specifiers given ind 'defSpec', which is default, 1 is first}
  88.         end;
  89.  
  90.       FUNCTION
  91.       tFileNameDlg.
  92.       {}
  93.       defExt :PChar;
  94.         begin
  95.           defExt := 'txt'  {override this to be the your default extension
  96.                             extension SHOULD NOT CONTAIN A PERIOD '.'}
  97.         end;
  98.  
  99.       FUNCTION
  100.       tFileNameDlg.
  101.       {}
  102.       openFlags:Longint;
  103.         begin
  104.             { this can be set to any OFN_ flags, but don't use the template related ones}
  105.           if toOpen
  106.           then
  107.             openFlags := OFN_PATHMUSTEXIST or OFN_HIDEREADONLY
  108.           else
  109.             openFlags := OFN_PATHMUSTEXIST or OFN_HIDEREADONLY
  110.                                            or OFN_NOREADONLYRETURN
  111.         end;
  112.  
  113.       FUNCTION
  114.       tFileNameDlg.
  115.       {}
  116.       doExec:Boolean;
  117.         begin
  118.           if toOpen
  119.           then
  120.             doExec := getOpenFileName(openFileName)
  121.           else
  122.             doExec := getSaveFileName(openFileName)
  123.         end;
  124.  
  125.  
  126.       FUNCTION
  127.       tFileNameDlg.
  128.       {}
  129.       execute:Integer;
  130.         var
  131.           result :Integer;
  132.           oldKBHandler :pWindowsObject;
  133.         begin
  134.           with openFileName do
  135.           begin
  136.             lStructSize   := sizeof(openFileName);
  137.             hInstance     := SYSTEM.HInstance;
  138.             if parent <> nil
  139.             then
  140.               hwndOwner   := parent^.hWindow
  141.             else
  142.               hwndOwner   := 0;
  143.             lpstrTitle    := dlgTitle;
  144.             lpTemplateName:= attr.Name;
  145.             lpstrFilter   := defSpec;
  146.             nFilterIndex  := defSpecPos;       {Index into Filter String in lpstrFilter}
  147.             lpstrDefExt   := defExt;
  148.             lpstrFile     := filePath;
  149.             lpstrFileTitle:= fileName;
  150.             flags         := openFlags;
  151.             if (lpTemplateName <> nil)
  152.             then
  153.               flags := flags or OFN_ENABLETEMPLATE
  154.             else
  155.               lpTemplateName := nil;
  156.             nMaxFile      := sizeOf(filePath);
  157.             nMaxFileTitle := sizeOf(fileName);
  158.  
  159.             lCustData    := Longint(@Self);  {this does nothing, but could be usefull}
  160.  
  161.             move(Self.instance, lpfnHook, sizeOf(lpfnHook)); {this does the trick!}
  162.  
  163.             flags := flags or OFN_ENABLEHOOK 
  164.           end;
  165.  
  166.           oldKbHandler := Application^.KBHandlerWnd;
  167.           isModal      := TRUE;  { this is very important, object gets freed twice otherwise !}
  168.           if doExec
  169.           then
  170.             execute := id_Ok
  171.           else begin
  172.             result := commDlgExtendedError;
  173.             if result = 0
  174.             then
  175.               execute := id_Cancel
  176.             else begin
  177.               execute := -result;
  178.               status  := em_InvalidWindow
  179.             end;
  180.           end;
  181.           hwindow := 0;
  182.           isModal := FALSE;
  183.           Application^.KBHandlerWnd := OldKbHandler;
  184.         end;
  185.  
  186.  
  187. END.